<!--
 * @Author: wangming
 * @Date: 2020-09-09 14:04:55
 * @LastEditors: wangming
 * @LastEditTime: 2021-03-31 15:34:34
 * @Description:添加类别按钮
-->
<template>
  <el-dialog :visible="showVisible" center :show-close="false" width="600px">
    <div class="b g3 f16 tl" slot="title">
      <div class="ks-row-between pl15 pr15">
        <span>新建列表页面</span>
        <span
          class="el-icon-close g9 f26 poi"
          @click="showVisible = false"
        ></span>
      </div>
    </div>
    <el-form
      class="pl30 pr30"
      :model="FormTypeData"
      inline
      ref="Form"
      label-width="120px"
    >
      <el-form-item
        label="列表名称"
        prop="name"
        :rules="[
          { required: true, message: '请输入表单名称', trigger: 'blur' },
          { validator, trigger: 'blur' },
        ]"
      >
        <el-input
          v-model="FormTypeData.name"
          style="width: 400px"
          placeholder="请输入表单名称"
        ></el-input>
      </el-form-item>
      <el-form-item
        label="关联模型"
        :rules="[
          { required: true, message: '请选择关联模型', trigger: 'change' },
        ]"
      >
        <el-select
          v-model="FormTypeData.region"
          placeholder="请选择关联模型"
          style="width: 400px"
        >
          <el-option label="区域一" value="shanghai"></el-option>
          <el-option label="区域二" value="beijing"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="列表页面描述">
        <el-input
          type="textarea"
          v-model="FormTypeData.name"
          style="width: 400px"
          placeholder="请输入列表页面描述"
        ></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="tr">
      <el-button @click="showVisible = false">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      showVisible: false,
      FormTypeData: { name: "" },
      callback: () => {},
      validator: (rule, value, callback) => {
        callback();
      },
    };
  },
  methods: {
    addForm() {
      this.FormTypeData = {};
      return this.showModel();
    },
    editForm(data) {
      this.FormTypeData = { data };
      return this.showModel();
    },
    showModel() {
      this.showVisible = true;
      this.$nextTick(() => {
        this.$refs.Form.clearValidate();
      });
      return {
        then: (callback) => {
          if (typeof callback === "function") {
            this.callback = callback;
          }
        },
      };
    },
    async submit() {
      try {
        await this.$refs.Form.validate();
        this.showVisible = false;
        this.callback();
      } catch (error) {}
    },
  },
};
</script>

<style lang="scss" scoped></style>
